package com.cy.pj.sys.controller;

import com.cy.pj.sys.common.util.ShiroUtils;
import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 张琪
 * @date 2020/11/13
 * @describe
 */

@RequestMapping("/")
@Controller
public class PageController {
    @Autowired
    private SysMenuService sysMenuService;

//    日志管理
    @GetMapping("/doIndexUI")
    public String doIndexUI(Model model) {
       /* SysUser user=ShiroUtils.getUser();
        model.addAttribute("user",user);*/
        SysUser sysUser =
                (SysUser) SecurityUtils.getSubject().getPrincipal();      //获取登陆用户
        List<SysUserMenu> list = sysMenuService.findUserMenusByUserId(sysUser.getId());
        model.addAttribute("username",sysUser.getUsername());
        model.addAttribute("userMenus", list);
        return "starter";
    }

    @GetMapping("/log/log_list")
    public String doLogList() {
        return "/sys/log_list";
    }

    @GetMapping("/doPageUI")
    public String doPageUI(){
        return "/common/page";
    }

    @GetMapping("/doLoginUI")
    public String doLoginUI(){
        return "login";
    }



//        菜单管理
//    固定路径的优先级最高,  如果找不到, 那么就找其他匹配的方法
//    @GetMapping("/menu/menu_list")
//    public String doMenuList(){
//        return "/sys/menu_list";
//    }

//    方便之后访问其他页面时能够更加的方便
    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable(required = false) String moduleUI) {
        return "sys/" + moduleUI;
    }


}
